<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);  
include_once dirname(dirname(dirname(__FILE__))).'/mgtv_init.php';
include_once dirname(dirname(dirname(__FILE__))).'/models/c2_task_model.php';
define('ORG_ID', 'jllt');

class mapping_program extends nn_timer
{

    public function action($params = null)
    {
        $this->msg('开始执行...');
        do_timer_action();
        $this->msg('执行结束...');
    }
}
$mapping_program = new mapping_program("mapping_program", ORG_ID);
$mapping_program->run();

function do_timer_action()
{
    set_time_limit(0);
    
    $file = fopen("program.csv","r");
    $i=2000;
    //$i_default=1000;
    $default = 1000;
    while(! feof($file))
    {
        $arr = (fgetcsv($file));
        if($arr[2]<$i){
            continue;
        }
        $item = array('nns_id'=>$arr[0],'nns_task_name'=>$arr[1]);
        $xml = '<?xml version="1.0" encoding="UTF-8"?><ADI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" BizDomain="2" Priority="1">
<Mappings><Mapping ParentType="Package" ParentID="mgtv_VOD" ElementType="Program" ElementID="'.$arr[0].'" Action="REGIST" ParentCode="mgtv_VOD" ElementCode="'.$arr[0].'" ><Property Name="ValidStart">20140101000000</Property><Property Name="ValidEnd">20540101000000</Property></Mapping></Mappings>
</ADI>';
    
        $i++;
        $default--;
        echo "No.".$i."--------------".$arr[1].PHP_EOL;
        c2_task_model::add_new_maping($item, $xml, 'jllt');
        if($default==0){
            break;
        }
    }
    fclose($file);
}

